﻿using System;
using TidyBlog.Data.Mapping;

namespace TidyBlog.Data
{
    /// <summary>
    /// 字段/值对
    /// </summary>
    public class ColumnValuePair
    {
        /// <summary>
        /// 获取或设置列名
        /// </summary>
        public string Name { get; set; }
        /// <summary>
        /// 获取或设置列值
        /// </summary>
        public string Value { get; set; }
        /// <summary>
        /// 获取或设置列值是否参数形式，默认为True
        /// </summary>
        public bool IsParamValue { get; set; }


        public ColumnValuePair()
        {
            SetDefaultValue();
        }
        /// <summary>
        /// 根据数据列特性初始化，列名和列值均与数据列特性的列名一致
        /// </summary>
        /// <param name="colAttr">数据列特性</param>
        public ColumnValuePair(ColumnAttribute colAttr)
        {
            Name = colAttr.Name;
            Value = colAttr.Name;

            SetDefaultValue();
        }
        /// <summary>
        /// 使用指定列名初始化
        /// </summary>
        /// <param name="colName">列名</param>
        public ColumnValuePair(string colName)
        {
            Name = colName;
            Value = colName;

            SetDefaultValue();
        }
        /// <summary>
        /// 根据列和值初始化，值为非参数
        /// </summary>
        /// <param name="column">列名</param>
        /// <param name="value">值</param>
        public ColumnValuePair(string colName, string colVal)
        {
            Name = colName;
            Value = colVal;

            SetDefaultValue();

            IsParamValue = false;
        }


        /// <summary>
        /// 设置默认值
        /// </summary>
        protected void SetDefaultValue()
        {
            IsParamValue = true;
        }
    }
}
